package workspace;

import java.util.Stack;

/**
 * @Description
 * @Author yangshunjie
 * @Date 2021/9/16
 */
public class test {
    public boolean isValidStr (String str) {
        // write code here
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < str.length(); i++) {
            char t = str.charAt(i);
            if(t=='<'||t=='{'||t=='['||t=='('){
                stack.push(t);
            }else{
                if(stack.isEmpty()){
                    return false;
                }
                char t2 = stack.pop();
                if((t=='>'&&t2=='<')||(t=='}'&&t2=='{')||(t==']'&&t2=='[')||(t==']'&&t2=='[')){

                }else{
                    return false;
                }
            }
        }
        if(stack.isEmpty()){
            return true;

        }else{
            return false;
        }
    }

}
